﻿using System;
using System.IO;
using log4net;
using log4net.Config;

namespace Groove.Core.Infrastructure
{
    /// <summary>
    /// LogWriter
    /// </summary>
    public class LogWriter
    {
        /// <summary>
        /// Default Logger
        /// </summary>
        public static ILog DefaultLogger => LogManager.GetLogger("DefaultLogger");

        /// <summary>
        /// Debug Logger
        /// </summary>
        public static ILog DebugLogger => LogManager.GetLogger("DebugLogger");
        
        /// <summary>
        /// Initialize
        /// </summary>
        public static void Init()
        {
            var configPath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "Log4Net.config");
            Init(configPath);
        }

        /// <summary>
        /// Initialize
        /// </summary>
        /// <param name="configPath">config file path</param>
        public static void Init(string configPath)
        {
            var logFile = new FileInfo(configPath);
            XmlConfigurator.Configure(logFile);
        }

        /// <summary>
        /// Log
        /// </summary>
        /// <param name="msg">Message</param>
        public static void Log(string msg)
        {
            DefaultLogger.Info(msg);
        }

        /// <summary>
        /// Warn
        /// </summary>
        /// <param name="msg">Message</param>
        /// <param name="ex">Exception</param>
        public static void Warn(string msg, Exception ex = null)
        {
            DefaultLogger.Warn(msg, ex);
        }

        /// <summary>
        /// Error
        /// </summary>
        /// <param name="msg">Message</param>
        /// <param name="ex">Exception</param>
        public static void Error(string msg, Exception ex)
        {
            DefaultLogger.Error(msg, ex);
        }

        /// <summary>
        /// Fatal
        /// </summary>
        /// <param name="msg">Message</param>
        /// <param name="ex">Exception</param>
        public static void Fatal(string msg, Exception ex = null)
        {
            DefaultLogger.Fatal(msg, ex);
        }

        /// <summary>
        /// Debug
        /// </summary>
        /// <param name="msg">Message</param>
        /// <param name="ex">Exception</param>
        public static void Debug(string msg, Exception ex = null)
        {
            DebugLogger.Debug(msg, ex);
        }
    }
}